package me.yricky.mayu.utils.fasta

/**
 * @author Yricky
 * @date 2022/9/30
 */
interface Parser{
    fun colorOf(c:Char):Long
    fun introOf(c:Char):String
    fun isExact(c:Char):Boolean
    companion object{
        val NAParser = object :Parser{
            override fun colorOf(c: Char):Long = when(c.uppercaseChar()){
                'A' -> 0x66ff3333
                'G' -> 0x6633cccc

                'C' -> 0x66999933
                'T','U' -> 0x66333399

                'R' -> 0x66cc9999
                'Y' -> 0x669999cc

                'K' -> 0x66663399
                'M' -> 0x66cc9933

                'S' -> 0x6699cc99
                'W' -> 0x66993399

                'B' -> 0x6600cccc
                'D' -> 0x663333cc
                'H' -> 0x66cc3333
                'V' -> 0x66cccc00

                ' ' -> 0

                else -> 0x66666666
            }

            override fun introOf(c: Char): String =when(c.uppercaseChar()){
                'A' -> "腺嘌呤（Adenine）"
                'T' -> "胸腺嘧啶（Thymine）"
                'C' -> "胞嘧啶（Cytosine）"
                'G' -> "鸟嘌呤（Guanine）"
                'U' -> "尿嘧啶（Uracil）"

                'R' -> "嘌呤（purine，A、G）"
                'Y' -> "嘧啶（pyrimidines，C、T、U）"

                'K' -> "酮基（ketones，G、T、U）"
                'M' -> "氨基（amino，A、C）"

                'S' -> "强（Strong）结合力（C、G）"
                'W' -> "弱（Weak）结合力（A、T、U）"

                'B' -> "非A（C、G、T、U）"
                'D' -> "非C（A、G、T、U）"
                'H' -> "非G（A、C、T、U）"
                'V' -> "非T非U（A、C、G）"

                'N' -> "任意核酸（Nucleic acid）"
                '-' -> "不定长片段"
                else -> "未知"
            }

            override fun isExact(c: Char): Boolean =when(c.uppercaseChar()){
                'A','T','C','G','U' -> true
                else -> false
            }
        }

        val PParser = object :Parser{
            override fun colorOf(c: Char):Long = when(c.uppercaseChar()){
                'A' -> 0x663333cc
                'B' -> 0x6633cc33
                'C' -> 0x66cc3333
                'D' -> 0x66669999
                'E' -> 0x66996699
                'F' -> 0x66999966
                'G' -> 0x66336699
                'H' -> 0x66339966
                'I' -> 0x66663399
                'J' -> 0x66669933
                'K' -> 0x66993366
                'L' -> 0x66996633
                'M' -> 0x66cc6633
                'N' -> 0x66cc3366
                'O' -> 0x6666cc33
                'P' -> 0x666633cc
                'Q' -> 0x663366cc
                'R' -> 0x6633cc66
                'S' -> 0x660099cc
                'T' -> 0x6600cc99
                'U' -> 0x66cc9900
                'V' -> 0x66cc0099
                'W' -> 0x669900cc
                'Y' -> 0x6699cc00
                'Z' -> 0x669999cc

                ' ' -> 0
                else -> 0x66666666
            }

            override fun introOf(c: Char): String =when(c.uppercaseChar()){
                'A' -> "丙氨酸（Alanine）"
                'B' -> "天冬氨酸（Aspartic acid，D）/天冬酰胺（Asparagine，N）"
                'C' -> "半胱氨酸（Cysteine）"
                'D' -> "天冬氨酸（Aspartic acid）"
                'E' -> "谷氨酸（Glutamic acid）"
                'F' -> "苯丙氨酸（Phenylalanine）"
                'G' -> "甘氨酸（Glycine）"
                'H' -> "组氨酸（Histidine）"
                'I' -> "异亮氨酸（Isoleucine）"
                'J' -> "亮氨酸（Leucine，L）/异亮氨酸（Isoleucine，I）"
                'K' -> "赖氨酸（Lysine）"
                'L' -> "亮氨酸（Leucine）"
                'M' -> "甲硫氨酸（Methionine）"
                'N' -> "天冬酰胺（Asparagine）"
                'O' -> "吡咯赖氨酸（Pyrrolysine）"
                'P' -> "脯氨酸（Proline）"
                'Q' -> "谷氨酰胺（Glutamine）"
                'R' -> "精氨酸（Arginine）"
                'S' -> "丝氨酸（Serine）"
                'T' -> "苏氨酸（Threonine）"
                'U' -> "硒半胱氨酸（Selenocysteine）"
                'V' -> "缬氨酸（Valine）"
                'W' -> "色氨酸（Tryptophan）"
                'Y' -> "酪氨酸（Tyrosine）"
                'Z' -> "谷氨酸（Glutamic acid，E）/谷氨酰胺（Glutamine，Q）"
                'X' -> "任意氨基酸"
                '*' -> "翻译终止"
                '-' -> "不定长片段"

                else -> "未知"
            }
            override fun isExact(c: Char): Boolean =when(c.uppercaseChar()){
                'A','C','D','E','F','G','H','I','K','L','M','N','O','P','Q','R','S','T','U','V','W','Y' -> true
                else -> false
            }
        }
    }
}